package teaching.mapper;

import org.apache.ibatis.annotations.*;
import teaching.pojo.Chapter;
import teaching.pojo.Point;
import teaching.pojo.Questions;

import java.util.List;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/3/12
 * Description:
 */

public interface ChapterMapper {

    @Insert("insert into chapter(cid,name,introduction,video) values (#{chapter.cid},#{chapter.name},#{chapter.introduction},#{chapter.video})")
    int add(@Param("chapter") Chapter chapter);

    @Delete("delete from chapter where id=#{id}")
    int deleteChapter(Long id);

    int updateChapter(@Param("chapter") Chapter chapter);

    @Update("ALTER TABLE `course` AUTO_INCREMENT = 1")
    void resetAutoIncrement();

    @Select("select * from chapter where cid=#{cid}")
    List<Chapter> getChapterbyCid(Long cid);

    @Select("select * from chapter where id=#{id}")
    Chapter getChapterbyId(Long id);

    @Delete("delete from chapter where cid=#{cid}")
    int deleteByCid(Long cid);

    // 插入章节
    int insertChapter(@Param("chapter") Chapter chapter);

    // 根据章节ID查询该章节对应的所有习题
    List<Questions> findQuestionsByChapterId(long chapterId);

    // 根据章节ID查询该章节对应的所有知识点
    List<Point> findPointsByChapterId(long chapterId);

    // 插入章节关联的知识点
    int insertChapterPoints(@Param("chapterId") long chapterId, @Param("pointIds") Long[] pointIds);

    // 插入章节关联的习题
    int insertChapterQuestions(@Param("chapterId") long chapterId, @Param("questionIds") Long[] questionIds);

}
